"""PAMR From Excel

.. helpdoc::
Generates a PAMR data container from Excel data.
"""


"""<widgetXML>
    <name>PAMR From Excel</name>
    <icon>default.png</icon>
    <tags>
        <tag>PAMR</tag>
    </tags>
    <summary>Generates a PAMR data container from Excel data.</summary>
    <author>
        <authorname>Red-R Core Development Team</authorname>
        <authorcontact>www.red-r.org</authorcontact>
    </author>
    </widgetXML>
"""

"""
<name>Read PAMR Data From Excel</name>
<author>Generated using Widget Maker written by Kyle R. Covington</author>
<tags>PAMR</tags>
"""
from OWRpy import * 
import OWGUI 
import redRGUI, signals
import libraries.pamr.signalClasses as pamrSignals
class pamr_from_excel(OWRpy): 
    settingsList = []
    def __init__(self, **kwargs):
        OWRpy.__init__(self, **kwargs)
        self.setRvariableNames(["pamr.from.excel"])
        self.RFunctionParam_sample_labels = "FALSE"
        self.RFunctionParam_batch_labels = "FALSE"
        self.RFunctionParam_file = ""
        self.RFunctionParam_ncols = ""
        
        """.. rrsignals::"""
        self.outputs.addOutput("pamr.from.excel Output", "PAMR Data Collection", signals.pamr.RPAMRData)
        
        """.. rrgui::"""
        self.RFunctionParamsample_labels_lineEdit =  redRRadioButtons(self.controlArea,  label = "Sample Labels:", buttons = ['Yes', 'No'], toolTip = 'Do Sample labels exist in the table', setChecked = 'No')
        
        """.. rrgui::"""
        self.RFunctionParambatch_labels_lineEdit =  redRRadioButtons(self.controlArea,  label = "Batch Labels:", buttons = ['Yes', 'No'], toolTip = 'Do Batch labels exist in the table', setChecked = 'No')
        
        """.. rrgui::"""
        redRButton(self.controlArea, "Load File", callback = self.loadFile)
        
        """.. rrgui::"""
        self.RFunctionParamfile_lineEdit =  redRLineEdit(self.controlArea,  label = "file:")
        
        """.. rrgui::"""
        self.RFunctionParamncols_lineEdit = redRLineEdit(self.controlArea, label = 'Number of Columns (required):')
        
        """.. rrgui::"""
        redRCommitButton(self.bottomAreaRight, "Commit", callback = self.commitFunction)
    def loadFile(self):
        file = self.R('(choose.files())')
        self.RFunctionParamfile_lineEdit.setText(unicode(file))
    def commitFunction(self):
        if unicode(self.RFunctionParamfile_lineEdit.text()) == '': return
        if unicode(self.RFunctionParamncols_lineEdit.text()) == '': return
        injection = []
        if 'Yes' == unicode(self.RFunctionParamsample_labels_lineEdit.getChecked()):
            string = 'sample_labels= TRUE'
        else:
            string = 'sample_labels= FALSE'
        injection.append(string)
        if 'Yes' == unicode(self.RFunctionParambatch_labels_lineEdit.getChecked()):
            string = 'batch_labels= TRUE'
        else:
            string = 'batch_labels= FALSE'
        injection.append(string)
        if unicode(self.RFunctionParamfile_lineEdit.text()) != '':
            string = 'file="'+unicode(self.RFunctionParamfile_lineEdit.text()).replace('\\','/')+'"'
            injection.append(string)
        inj = ','.join(injection)
        self.R(self.Rvariables['pamr.from.excel']+'<-pamr.from.excel('+inj+')')
        newData = signals.pamr.RPAMRData(self, data = self.Rvariables['pamr.from.excel'])
        self.rSend("pamr.from.excel Output", newData)
